//
//  NSHomeNullView.m
//  Meboo
//
//  Created by kyo on 2024/4/3.
//

#import "NSHomeNullView.h"
#import "NSTimeView.h"
@interface NSHomeNullView ()
@property (nonatomic, strong) UIView *noDataView;
@property (nonatomic, strong) UIImageView *noDataImageView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *subTitleLab;
@property (nonatomic, strong) UIButton *continueBtn;


@property (nonatomic, strong) UIView *CountdownView;
@property (nonatomic, strong) UIImageView *cdNoDataImageView;
@property (nonatomic, strong) UILabel *cdTitleLab;
@property (nonatomic, strong) UILabel *cdSubTitleLab;
@property (nonatomic, strong) UIButton *cdContinueBtn;
@property (nonatomic, strong) NSTimeView *timeView;
@end

@implementation NSHomeNullView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Action

- (void)nextAction {
    if (self.refreshTime > 0) {
        if (self.popBlock) {
            self.popBlock(NO);
        }
    } else {
        self.currentViewController.tabBarController.selectedIndex = 1;
        if (self.refreshBlock) {
            self.refreshBlock();
        }
    }
}

- (void)setRefreshTime:(NSInteger)refreshTime {
    _refreshTime = refreshTime;
    if (refreshTime <= 0) {
        self.noDataView.hidden = NO;
        self.CountdownView.hidden = YES;
    } else {
        self.timeView.second = refreshTime;
        [self.timeView startCount];
        self.noDataView.hidden = YES;
        self.CountdownView.hidden = NO;
        self.cdTitleLab.text = [MBWhoLikeMeDataManager sharedManager].title;
    }
}

#pragma mark - UI
- (void)setupUI {
    
    self.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.noDataView];
    [self.noDataView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.noDataView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(44));
        make.right.mas_equalTo(MBWidthScale(-44));
        make.bottom.equalTo(self.noDataView.mas_centerY).offset(MBHeightScale(17));
    }];
    
    [self.noDataView addSubview:self.noDataImageView];
    [self.noDataImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.noDataView);
        make.bottom.equalTo(self.titleLab.mas_top).offset(MBHeightScale(-30));
        make.height.width.mas_equalTo(MBWidthScale(163));
    }];
    
    [self.noDataView addSubview:self.subTitleLab];
    [self.subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(44));
        make.right.mas_equalTo(MBWidthScale(-44));
        make.top.equalTo(self.noDataView.mas_centerY).offset(MBHeightScale(33));
    }];
    
    [self.noDataView addSubview:self.continueBtn];
    [self.continueBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.noDataView);
        make.width.mas_equalTo(MBWidthScale(200));
        make.height.mas_equalTo(MBHeightScale(52));
        make.top.equalTo(self.subTitleLab.mas_bottom).offset(MBHeightScale(30));
    }];
    
    
    
    
    [self addSubview:self.CountdownView];
    [self.CountdownView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.CountdownView addSubview:self.cdTitleLab];
    [self.cdTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(27));
        make.right.mas_equalTo(MBWidthScale(-27));
        make.centerY.equalTo(self.CountdownView);
    }];
    
    [self.CountdownView addSubview:self.cdNoDataImageView];
    [self.cdNoDataImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.CountdownView);
        make.bottom.equalTo(self.cdTitleLab.mas_top).offset(MBHeightScale(-55));
        make.width.mas_equalTo(MBWidthScale(189));
        make.height.mas_equalTo(MBWidthScale(175));
    }];
    
    [self.CountdownView addSubview:self.timeView];
    [self.timeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(42));
        make.right.mas_equalTo(MBWidthScale(-42));
        make.height.mas_equalTo(MBHeightScale(50));
        make.top.equalTo(self.cdTitleLab.mas_bottom).offset(MBHeightScale(22));
    }];
    
    [self.CountdownView addSubview:self.cdSubTitleLab];
    [self.cdSubTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(27));
        make.right.mas_equalTo(MBWidthScale(-27));
        make.top.equalTo(self.timeView.mas_bottom).offset(MBHeightScale(16));
    }];
    
    [self.CountdownView addSubview:self.cdContinueBtn];
    [self.cdContinueBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(42));
        make.right.mas_equalTo(MBWidthScale(-42));
        make.height.mas_equalTo(MBHeightScale(52));
        make.top.equalTo(self.cdSubTitleLab.mas_bottom).offset(MBHeightScale(53));
    }];
}

#pragma mark - Setter && Getter
//nodata
- (UIView *)noDataView {
    if (!_noDataView) {
        _noDataView = [UIView new];
        _noDataView.backgroundColor = UIColor.clearColor;
    }
    return _noDataView;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.numberOfLines = 0;
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.text = @"Did you miss out on many people?";
        _titleLab.font = MBHelBoldFontSizeScale(18);
        _titleLab.textColor = HEXS(@"000000");
    }
    return _titleLab;
}

- (UILabel *)subTitleLab {
    if (!_subTitleLab) {
        _subTitleLab = [UILabel new];
        _subTitleLab.numberOfLines = 0;
        _subTitleLab.textAlignment = NSTextAlignmentCenter;
        _subTitleLab.text = @"All sweethearts who approach you are fair game😈";
        _subTitleLab.font = MBHelFontSizeScale(15);
        _subTitleLab.textColor = HEXS(@"84868E");
    }
    return _subTitleLab;
}

- (UIButton *)continueBtn {
    if (!_continueBtn) {
        _continueBtn = [UIButton new];
        [_continueBtn setBackgroundColor:HEXS(@"B92176")];
        _continueBtn.layer.cornerRadius = MBHeightScale(52/2);
        [_continueBtn setTitle:@"Go flirt with All" forState:0];
        [_continueBtn setTitleColor:HEXS(@"ffffff") forState:0];
        _continueBtn.titleLabel.font = MBHelBoldFontSizeScale(16);
        [_continueBtn addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _continueBtn;
}

- (UIImageView *)noDataImageView {
    if (!_noDataImageView) {
        _noDataImageView = [UIImageView new];
        _noDataImageView.contentMode = UIViewContentModeScaleAspectFill;
        _noDataImageView.image = ImageWithName(@"home_list_nodata_icon");
    }
    return _noDataImageView;
}

//countdown
- (UIView *)CountdownView {
    if (!_CountdownView) {
        _CountdownView = [UIView new];
        _CountdownView.backgroundColor = UIColor.clearColor;
        _CountdownView.hidden = YES;
    }
    return _CountdownView;
}

- (UILabel *)cdTitleLab {
    if (!_cdTitleLab) {
        _cdTitleLab = [UILabel new];
        _cdTitleLab.textAlignment = NSTextAlignmentCenter;
        _cdTitleLab.text = @"OOPS! No More Match";
        _cdTitleLab.font = MBHelBoldFontSizeScale(24);
        _cdTitleLab.textColor = HEXS(@"000000");
    }
    return _cdTitleLab;
}

- (UILabel *)cdSubTitleLab {
    if (!_cdSubTitleLab) {
        _cdSubTitleLab = [UILabel new];
        _cdSubTitleLab.textAlignment = NSTextAlignmentCenter;
        _cdSubTitleLab.text = @"Refresh times after";
        _cdSubTitleLab.font = MBHelFontSizeScale(18);
        _cdSubTitleLab.textColor = HEXS(@"84868E");
    }
    return _cdSubTitleLab;
}

- (UIButton *)cdContinueBtn {
    if (!_cdContinueBtn) {
        _cdContinueBtn = [UIButton new];
        [_cdContinueBtn setBackgroundColor:HEXS(@"B92176")];
        _cdContinueBtn.layer.cornerRadius = MBHeightScale(52/2);
        [_cdContinueBtn setTitle:@"Unlock Now" forState:0];
        [_cdContinueBtn setTitleColor:HEXS(@"ffffff") forState:0];
        _cdContinueBtn.titleLabel.font = MBHelBoldFontSizeScale(16);
        [_cdContinueBtn addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cdContinueBtn;
}

- (UIImageView *)cdNoDataImageView {
    if (!_cdNoDataImageView) {
        _cdNoDataImageView = [UIImageView new];
        _cdNoDataImageView.contentMode = UIViewContentModeScaleAspectFill;
        _cdNoDataImageView.image = ImageWithName(@"home_nodata_time_icon");
    }
    return _cdNoDataImageView;
}

- (NSTimeView *)timeView {
    if (!_timeView) {
        __WeakSelf
        _timeView = [NSTimeView new];
        _timeView.timeBlock = ^{
            if (weakSelf.popBlock) {
                weakSelf.popBlock(YES);
            }
        };
    }
    return _timeView;
}
@end
